package com.caterina.activities;
import java.awt.BorderLayout;
import java.awt.Container;
import com.caterina.activityManager.CActivity;
import com.caterina.components.CButton;
import com.caterina.components.CLabel;
import com.caterina.components.CLogo;
import com.caterina.components.COptionPane.MessageType;
import com.caterina.components.CPanel;
import com.caterina.components.CTextField;
import com.caterina.resources.CWords;
import controllers.ManagerTask.TaskType;
public class InstallationActivity extends CActivity{
	public InstallationActivity(Container parent) {
		super("FIRST_CONFIG",parent);
		this.setCBarVisible(false);
		this.setCBarQueryesEnabled(false);
	}
	@Override
	public void onData(TaskType task, Object data) {
		switch(task){
			case SYSTEM_SET_SYS_USER:{this.getActivityManager().switchActivity(new LoginActivity(getParentContainer()));break;}
		default:break;
		}
		
	}
	@Override
	public void onError(TaskType task, Exception e) {
		switch(task){
		case SYSTEM_SET_SYS_USER:{btn.setText(CWords.getWord("SYS_ADMIN_INSERT_ADMIN"));showCOPtionPane(MessageType.ERROR, CWords.getWord("SYS_REGISTER_ERROR"));break;}
		default:break;
	}
	}
	@Override
	public void onStart() {
		CPanel mainPanel=new CPanel(new BorderLayout());
		this.add(mainPanel);
		mainPanel.add(this.getLogoPanel(),BorderLayout.NORTH);
		mainPanel.add(this.getWellComePanel(),BorderLayout.CENTER);
		mainPanel.add(this.getLoginPanel(),BorderLayout.SOUTH);

	}
	private CPanel getLogoPanel(){
		CPanel lPanel= new CPanel();
		lPanel.add(new CLogo(400,110));
		return lPanel;
	}
	private CPanel getWellComePanel(){
		CPanel mainPanel=new CPanel();
		mainPanel.add(new CLabel(CWords.getWord("WELLCOME_TEXT")));
		return mainPanel;
	}
	private CPanel getLoginPanel(){
		CPanel mainPanel=new CPanel();
		mainPanel.add(login);
		mainPanel.add(password);
		mainPanel.add(btn);
		return mainPanel;
	}
	private CTextField login=new CTextField("", 20,CWords.getWord("SYS_ADMIN_USER_NAME"));
	private CTextField password =new CTextField("", 20,CWords.getWord("SYS_ADMIN_PASSWORD"));
	private CButton btn=new CButton(CWords.getWord("SYS_ADMIN_INSERT_ADMIN")) {
		@Override
		public void onFocus() {}
		@Override
		public void onAction() {
			if(login.getText().equals("")||password.getText().equals("")){
				showCOPtionPane(MessageType.ERROR, CWords.getWord("SYS_NULL_VALUES"));
			}
			else{
				this.setText(CWords.getWord("SYS_REGISTRATION"));
				putTask(TaskType.SYSTEM_SET_SYS_USER, login.getText(),password.getText());
			}
		}
		private static final long serialVersionUID = 1L;
	};
	private static final long serialVersionUID = 1L;
}
